﻿using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using StartEAS_API.Utils;
using StartsEAS_API.BLL.Interfaces.IWorkerEvaluationB;
using StartsEAS_API.Model;

namespace StartsEAS_API.Controllers.WorkerEvaluationContor
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [EnableCors("any")]
    public class WorkerEvaluationController : ControllerBase
    {
        private readonly IWorkerEvaluationBLL _workerEvaluationBLL;

        public WorkerEvaluationController(IWorkerEvaluationBLL workerEvaluationBLL) {
            _workerEvaluationBLL = workerEvaluationBLL;
        }
        /// <summary>
        /// 查询当前所有教师评价表
        /// </summary>
        /// <param name="token">学生token，教务处token</param>
        /// <returns></returns>
        [HttpGet]
        public ResultUtils GetWorkerEvaluation(string token) {
            try
            {
                return _workerEvaluationBLL.GetWorkerEvaluation(token);
            }
            catch (System.Exception e)
            {
                AppLog.WriteError($"GetWorkerEvaluation服务器内部异常：{e}", true);
                return new ResultUtils() { code = 500, message = $"服务器内部异常\n{e.Message}" };
            }
        }
        /// <summary>
        /// 根据教职工编号查询教评
        /// </summary>
        /// <param name="token">教务处token</param>
        /// <param name="workerId">教职工编号</param>
        /// <returns></returns>
        [HttpGet]
        public ResultUtils GetWorkerEvaluationsByWorkerId(string token, string workerId) {
            try
            {
                return _workerEvaluationBLL.GetWorkerEvaluationsByWorkerId(token, workerId);
            }
            catch (System.Exception e)
            {
                AppLog.WriteError($"GetWorkerEvaluationsByWorkerId服务器内部异常：{e}", true);
                return new ResultUtils() { code = 500, message = $"服务器内部异常\n{e.Message}" };
            }
        }
        /// <summary>
        /// 根据学生编号查询教师评价表
        /// </summary>
        /// <param name="token">教务处token</param>
        /// <param name="StuId">学生编号</param>
        /// <returns></returns>
        [HttpGet]
        public ResultUtils GetWorkerEvaluationsByStuId(string token, string StuId) {
            try
            {
                return _workerEvaluationBLL.GetWorkerEvaluationsByStuId(token, StuId);
            }
            catch (System.Exception e)
            {
                AppLog.WriteError($"GetWorkerEvaluationsByStuId服务器内部异常：{e}", true);
                return new ResultUtils() { code = 500, message = $"服务器内部异常\n{e.Message}" };
            }
        }
        /// <summary>
        /// 根据课程编号查询教师评价表
        /// </summary>
        /// <param name="token">教务处token</param>
        /// <param name="CourseId">课程编号</param>
        /// <returns></returns>
        [HttpGet]
        public ResultUtils GetWorkerEvaluationsByCourseId(string token, int CourseId) {
            try
            {
                return _workerEvaluationBLL.GetWorkerEvaluationsByCourseId(token, CourseId);
            }
            catch (System.Exception e)
            {
                AppLog.WriteError($"GetWorkerEvaluationsByCourseId服务器内部异常：{e}", true);
                return new ResultUtils() { code = 500, message = $"服务器内部异常\n{e.Message}" };
            }
        }
        /// <summary>
        /// 添加教室评价表
        /// </summary>
        /// <param name="token">学生token</param>
        /// <param name="workerEvaluation">教师评价表</param>
        /// <returns></returns>
        [HttpPost]
        public ResultUtils AddWorkerEvaluation(string token, JObject workerEvaluation) {
            try
            {
                return _workerEvaluationBLL.AddWorkerEvaluation(token, workerEvaluation);
            }
            catch (System.Exception e)
            {
                AppLog.WriteError($"AddWorkerEvaluation服务器内部异常：{e}", true);
                return new ResultUtils() { code = 500, message = $"服务器内部异常\n{e.Message}" };
            }
        }
    }
}
